<?php
include_once '../../mainfile.php';
include (XOOPS_ROOT_PATH . "/header.php");
require ("include/xmlwriterclass.php");
require ("include/rss_writer_class.php");

/*
 *  First create an object of the class. 
 */
$rss_writer_object = & new rss_writer_class;

/*
 *  Choose the version of specification that the generated RSS document should conform.
 */
$rss_writer_object->specification = '1.0';

/*
 *  Specify the URL where the RSS document will be made available.
 */
$rss_writer_object->about = XOOPS_URL . '/modules/local_news/channels.xml';

/*
 *  Specify the URL of an optional XSL stylesheet.
 *  This lets the document be rendered automatically in XML capable browsers.
 */
$rss_writer_object->stylesheet = XOOPS_URL . '/modules/local_news/include/rss1html.xsl';

/*
 *  You may declare additional namespaces that enable the use of more property
 *  tags defined by extension modules of the RSS specification.
 */
$rss_writer_object->rssnamespaces['dc'] = 'http://purl.org/dc/elements/1.1/';

/*
 *  Define the properties of the channel.
 */
$properties = array ();
$properties['description'] = $xoopsModuleConfig['stationLetters'] . ' Local News Stories';
$properties['link'] = XOOPS_URL;
$properties['title'] = $xoopsModuleConfig['stationLetters'] . '-FM Local News Feeds';
$properties['dc:date'] = date("m/d/Y");
$rss_writer_object->addchannel($properties);

/*
 *  If your channel has a logo, before adding any channel items, specify the logo details this way.
 */
/*$properties = array ();
$properties['url'] = 'http://www.phpclasses.org/graphics/logo.gif';
$properties['link'] = 'http://www.phpclasses.org/';
$properties['title'] = 'PHP Classes repository logo';
$properties['description'] = 'Repository of components and other resources for PHP developers';
$rss_writer_object->addimage($properties);
*/

/*
 *  Then add your channel items one by one.
 */

$result = $xoopsDB->query("SELECT ID, tease, publish_date, headline, dateline FROM " . $xoopsDB->prefix("local_news_stories") . " ORDER BY publish_date DESC LIMIT " . $xoopsModuleConfig['NISL'] . "");
if ($result) {
	$properties = array ();
	while ($myrow = $xoopsDB->fetchArray($result)) {
		$properties['description'] = $myrow['dateline']." (".date("m/d/Y",$myrow['publish_date']).") ". html_entity_decode($myrow['tease'], ENT_QUOTES, 'UTF-8');
		$properties['link'] = XOOPS_URL . '/modules/local_news/index.php?op=sideBlock&ID=' . $myrow['ID'];
		$properties['title'] = html_entity_decode($myrow['headline'], ENT_QUOTES, 'UTF-8');
		$properties['dc:date'] = date("m/d/Y",$myrow['publish_date']);
		$rss_writer_object->additem($properties);


	}

}

/*
 *  If your channel has a search page, after adding the channel items, specify a search form details this way.
 */

/*
 *  The name property if the name of the text input form field on which the user will enter the search word.
 */
/*
$properties['name'] = 'words';
$properties['link'] = 'http://www.phpclasses.org/search.html?go_search=1';
$properties['title'] = 'Search for:';
$properties['description'] = 'Search in the PHP Classes repository';
$rss_writer_object->addtextinput($properties);
*/
/*
 *  When you are done with the definition of the channel items, generate RSS document.
 */
if ($rss_writer_object->writerss($output)) {

	/*
	 *  If the document was generated successfully, you may now output it.
	 */
		Header('Content-Type: text/xml; charset="' . $rss_writer_object->outputencoding . '"');
		Header('Content-Length: ' . strval(strlen($output)));
		echo $output;
} else {

	/*
	 *  If there was an error, output it as well.
	 */
	Header('Content-Type: text/plain');
	echo ('Error: ' . $rss_writer_object->error);
}
?>